<?php

class settings extends ci_controller
{

	function __construct(){
		
		parent::__construct();
		$this->load->library('tank_auth');
		$this->load->library('bara_lib');
		$this->load->model('user');
		$this->load->model('admin/setting');

		if (!$this->tank_auth->is_logged_in()) redirect('/auth/login/');
		
		$this->lang->load('tank_auth');
	
	}

	function index(){

		$this->bara_lib->check_permission_show($this->tank_auth->get_user_id(), 'setting');
		

		$data['content'] = 'admin/settings/index';
		$this->load->view('layout/backend', $data);
	}

	function pagination(){
        if ($_GET['page']) {
            $page = $_GET['page'];

            $data['cur_page'] = $page;
            $cur_page = $page;
            $page -= 1;
            $per_page = 10;
            $data['per_page'] = $per_page;
            $start = $page * $per_page;
            $query = $this->setting->data_pagination($start, $per_page);

            $count = $this->setting->pagination();
            $data['no_of_paginations'] = ceil($count / $per_page);

            $data['rows'] = $query;
            $data['count'] = count($query);
            $this->load->view('admin/settings/pagination', $data);
        }
	}

	function config(){
		$this->bara_lib->check_permission_update($this->tank_auth->get_user_id(), 'setting');

		$key = $this->uri->segment(4);
		$id = $this->uri->segment(5);

		$data['rows'] = $this->setting->get_config($id);
		
		$data['content'] = 'admin/settings/'.$key;
		$this->load->view('layout/backend', $data);
	}

	function update(){
		$this->bara_lib->check_permission_update($this->tank_auth->get_user_id(), 'setting');
	
			$id = $this->input->post('id_kategori_sub');

			$gets_set = $this->setting->get_config($id);

			foreach ($gets_set as $key => $get_set) {
				$where = array('id_setting_website_language' => $get_set->id_setting_website_language);
				$data = array(
					'content_setting_website' => $this->input->post($get_set->id_setting_website_language)
					);

				$this->user->update('setting_website_language', $where, $data);
			}

			redirect('admin/settings/index');
	}


}

?>